package com.cssw.fyzb.wap.controller;

import com.cssw.fyzb.base.web.context.UserContext;
import com.cssw.fyzb.base.web.domain.AjaxData;
import com.cssw.fyzb.base.web.domain.AjaxPage;
import com.cssw.fyzb.wap.model.dto.CollectTaskDto;
import com.cssw.fyzb.wap.model.dto.ViewDailyTaskDto;
import com.cssw.fyzb.wap.model.dto.ViewTaskVideoDto;
import com.cssw.fyzb.wap.model.vo.*;
import com.cssw.fyzb.wap.service.TaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/**
 * @Auther: zzf
 * @Date: 2020/12/15 17:26
 * @Description:
 */
@Api(description = "任务相关接口")
@Controller
@RequestMapping("/task")
public class TaskController {

    private static final Logger logger = LoggerFactory.getLogger(TaskController.class);

    //未结算
    private static final String NO_STATUS = "1";

    //已结算
    private static final String SETTLED_STATUS = "2";

    //过期
    private static final String OVER_STATUS = "3";

    @Autowired
    private TaskService taskService;

    @ApiOperation(value = "任务中心")
    @RequestMapping(value = "/taskList", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),

    })
    @ResponseBody
    public AjaxPage<TaskVo> taskList(int pageNumber, int pageSize) {
        return taskService.taskList(UserContext.getUserId(), pageNumber, pageSize);
    }

    @ApiOperation(value = "我的任务")
    @RequestMapping(value = "/myTaskList", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),

    })
    @ResponseBody
    public AjaxPage<TaskVo> myTaskList(int pageNumber, int pageSize) {
        return taskService.myTaskList(UserContext.getUserId(), pageNumber, pageSize);
    }

    @ApiOperation(value = "历史任务")
    @RequestMapping(value = "/oldTask", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),
    })
    @ResponseBody
    public AjaxPage<TaskVo> oldTask(int pageNumber, int pageSize) {
        return taskService.oldTask(UserContext.getUserId(), pageNumber, pageSize);
    }

    @ApiOperation(value = "领取任务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务标识", paramType = "query", dataType = "string")
    })
    @RequestMapping(value = "/collectTask", method = RequestMethod.POST)
    @ResponseBody
    public AjaxData<CollecTaskVo> collectTask(@RequestBody CollectTaskDto dto) {
        return taskService.collectTask(UserContext.getUserId(), dto.getTaskId(), dto.getPwd());
    }

    @ApiOperation(value = "今日任务进度")
    @RequestMapping(value = "/taskProcess", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),
    })
    @ResponseBody
    public AjaxData<TodayTaskProcessVo> taskProcess(int pageNumber, int pageSize) {
        return taskService.todayTask(UserContext.getUserId(), pageNumber, pageSize);
    }

    @ApiOperation(value = "平安果展示")
    @RequestMapping(value = "/valueExhibition", method = RequestMethod.GET)
    @ResponseBody
    public AjaxData<ValueSettlementVo> valueExhibition() {
        return taskService.valueExhibition(UserContext.getUserId());
    }

    @ApiOperation(value = "未结算任务展示")
    @RequestMapping(value = "/listTaskExec", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),
    })
    @ResponseBody
    public AjaxPage<TaskExecVo> noTaskExec(int pageNumber, int pageSize) {
        return taskService.listTaskExec(UserContext.getUserId(), pageNumber, pageSize, NO_STATUS);
    }

    @ApiOperation(value = "已结算任务展示")
    @RequestMapping(value = "/settledTaskExec", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),
    })
    @ResponseBody
    public AjaxPage<TaskExecVo> settledTaskExec(int pageNumber, int pageSize) {
        return taskService.listTaskExec(UserContext.getUserId(), pageNumber, pageSize, SETTLED_STATUS);
    }

    @ApiOperation(value = "过期任务展示")
    @RequestMapping(value = "/overTaskExec", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),
    })
    @ResponseBody
    public AjaxPage<TaskExecVo> overTaskExec(int pageNumber, int pageSize) {
        return taskService.listTaskExec(UserContext.getUserId(), pageNumber, pageSize, OVER_STATUS);
    }

    @ApiOperation(value = "每日任务")
    @RequestMapping(value = "/dailyTasks", method = RequestMethod.GET)
    @ResponseBody
    public AjaxData<DailyTasksVo> dailyTasks() {
        return taskService.dailyTasks(UserContext.getUserId());
    }

    @ApiOperation(value = "一键结算")
    @RequestMapping(value = "/settlement", method = RequestMethod.POST)
    @ResponseBody
    public AjaxData settlement() {
        return taskService.settlement(UserContext.getUserId());
    }


    @ApiOperation(value = "任务看视频统计")
    @RequestMapping(value = "/viewVideoCount", method = RequestMethod.POST)
    @ResponseBody
    public AjaxData viewVideoCount(@RequestBody ViewTaskVideoDto dto) {
        return taskService.viewVideoCount(UserContext.getUserId(), dto.getAdvertId(), dto.getTimeLong());
    }

    @ApiOperation(value = "任务看视频时间统计")
    @RequestMapping(value = "/videoDayTask", method = RequestMethod.POST)
    @ResponseBody
    public AjaxData videoDayTask(@RequestBody ViewTaskVideoDto dto) {
        return taskService.videoDayTask(UserContext.getUserId(), dto.getTimeLong());
    }

    @ApiOperation(value = "用户是否设置交易密码")
    @RequestMapping(value = "/userTransactionPwd", method = RequestMethod.GET)
    @ResponseBody
    public AjaxData<UserTransactionPwdVo> userTransactionPwd() {
        return taskService.userTransactionPwd(UserContext.getUserId());
    }

    @ApiOperation(value = "观看每日任务广告")
    @RequestMapping(value = "/viewDailyTask", method = RequestMethod.POST)
    @ResponseBody
    public AjaxData viewDailyTask(@RequestBody ViewDailyTaskDto dto) {
        return taskService.viewDailyTask(UserContext.getUserId(), dto.getAdvert());
    }

    @ApiOperation(value = "三条广告每日任务完成情况")
    @RequestMapping(value = "/onDayTask", method = RequestMethod.GET)
    @ResponseBody
    public AjaxData<OnDayTaskVo> onDayTask() {
        return taskService.onDayTask(UserContext.getUserId());
    }


    @ApiOperation(value = "根据类型查看任务说明")
    @RequestMapping(value = "/getTaskDescByType", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskType", value = "任务类型（1-书卷任务 2-游戏任务 3-转发任务 4-活动任务 5-广告任务）", paramType = "query", dataType = "int", required = true),
    })
    @ResponseBody
    public AjaxData<TaskDescVo> getTaskDescByType(String taskType) {
        return taskService.getTaskDescByType(UserContext.getUserId(), taskType);
    }
}
